package com.demo.proxy.service1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @description:
 * @className: CarHandler
 * @package: com.demo.proxy.service1
 * @author: dongww@hsyuntai.com
 * @date: 2019/4/3 16:57
 * @copyright: 版权归 HSYUNTAI 所有
 */
public class CarHandler implements InvocationHandler {

    private Car car;

    public CarHandler(Car car) {
        this.car = car;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before");
//        if (method.getName().equals("drive")) {
//            System.out.println("行驶");
              method.invoke(car, args);
//        }

//        if (method.getName().equals("stop")) {
//            System.out.println("停车");
//            return  method.invoke(car, args);
//        }

        System.out.println("after");
        return  null;
    }

}
